package cn.tedu.batch.transformation

import org.apache.flink.api.scala.ExecutionEnvironment

/**
 * @author Amos
 * @date 2022/5/19
 */

// MapPartition算子
object BatchMapPartitionDemo {
  def main(args: Array[String]): Unit = {
    val env = ExecutionEnvironment.getExecutionEnvironment
    import org.apache.flink.api.scala._
    val source = env.fromElements("1,张三", "2,李四", "3,王五", "4,赵六")

    // 按照分区做数据的转换
    val result = source.mapPartition(iter => {
      // 对分区内的数据操作
      iter.map(ele => {
        // 拆分
        val fields = ele.split(",")
        User(fields(0).toInt, fields(1))
      })
    })

    result.print()
  }

}
